﻿// -------------------------------------------------------------------------
//    @FileName         :    NFMapPart.h
//    @Author           :    gaoyi
//    @Date             :    24-8-30
//    @Email            :    445267987@qq.com
//    @Module           :    NFMapPart
//
// -------------------------------------------------------------------------

#pragma once

#include <NFLogicCommon/NFLogicShmTypeDefines.h>
#include "NFPart.h"
#include "proto_common_base.nanopb.h"

class NFMapPart : public NF_OBJECT_TEMPLATE_MACRO(NFMapPart, EOT_LOGIC_PART_MIN_ID + PART_MAP, NFPart)
public:
    NFMapPart();

    ~NFMapPart() override;

    int CreateInit();
    int ResumeInit();

public:
    //******************part调用接口******************
    /**
     * @brief 所有部件初始化完成
     * @return
     */
    int OnInit() override
    {
        return 0;
    }

public:
    /**
     * @brief 从数据库中加载数据
     * @param data
     * @return
     */
    int LoadFromDB(const proto_ff::tbRoleDetail* pDbData) override;

    /**
     * @brief 从配置中初始化数据
     * @return
     */
    int InitConfig(proto_ff::tbRoleDetail* pDbData, const RoleOne& stRoleOne) override;

    /**
     * @brief 存储DB部件入口
     * @param proto
     * @return
     */
    int SaveDB(proto_ff::tbRoleDetail* pDbData) override;

    /**
     * @brief 登陆入口
     * @return
     */
    int OnLogin() override;

    /**
     * @brief 登出入口
     * @return
     */
    int OnLogout() override
    {
        return 0;
    }

    /**
     * @brief 掉线入口
     * @return
     */
    int OnDisconnect() override
    {
        return 0;
    }

    /**
     * @brief 重连入口
     * @return
     */
    int OnReconnect() override
    {
        return 0;
    }

    ////////////////////////////////// 每日零点 每周一零点 刷新接口 ///////////////////////////////////
    /**
     * @brief 每日零点 刷新接口
     * @return
     */
    int DayTick() override
    {
        return 0;
    }

    /**
     * @brief 每日零点 刷新接口
     * @return
     */
    int WeekTick() override
    {
        return 0;
    }

    /**
     * @brief 每月刷新接口
     * @return
     */
    int MonthTick() override
    {
        return 0;
    };

public:
    /**
     * @brief update
     */
    int LogicTick();

public:
    int MakePlayerDataCS(proto_ff::Proto_CSGetRoleRsp* pCsGetRoleRsp) override;
    int MakeCityPlayerData(proto_ff::CityRoleInfo* pGcCityRoleInfo) override;
    int SynMapData(const proto_ff::RoleMapData *pRoleMapData);
public:
    void SetEnterCity(bool bSet);
    bool IsEnterCity() const;
    void SetStateLeave(bool bSet);
    bool IsStateLeave() const;
    void MarkCitySynDirty();
    bool IsNeedSyn2City() const;
    bool IsInCitySyn() const;
    void SetCitySyn(bool bSet);
    int GetCurSynSeq() const;
    void SetSynSeq(int iSynSeq);
    int GetMapInstId() const;
    void SetMapInstId(int iMapInstId);
    const RoleMapData* GetMapData() const;
    RoleMapData* GetMapData();
    void SetInTransMap(bool bSet);
    bool IsInTransMap() const;

    void SetRoleObjID(int iObjID);
    int GetRoleObjID();

public:
    int AddEnterCity( int iMapId );
    bool FindEnterCity( int iMapId );
    bool IsEnterCityFull() { return m_stCityEnterData.enter_map_id.full(); }
private:
    RoleMapData m_stMapData;
    RoleCityEnterData m_stCityEnterData;

    int m_iRoleObjID;
    int m_iMapInstId;
    int m_iCityCurSeq;
    int m_iCitySyncSeq;
    bool m_bInSync;

    bool m_bEnterCity;
    bool m_bInTransMap;

    bool m_bStateLeave;
};


